<template>
	<view class="scrollbox">
		<u-navbar title="企业资料">
			<template #right>
				<view class="edtbtn" @click="onedt"> 添加 </view>
			</template>
		</u-navbar>
		<getdatascrollview ref="getdatascrollview" :api="api" :seardata="tablequery">
			<template #default="{ list }">
				<view class="searchcontent">
					<deptSelect style="flex: 1;" v-model="searchdata.deptId" @change="change"></deptSelect>
					<view class="sx" @click="sxfn">
						筛选<u-icon name="arrow-down"></u-icon>
					</view>
				</view>
				<listcard v-for="item in list" :item="item" :list="listinputs">
					<template #before> {{ item.deptName }} </template>
					<template #after>
						<view class="u-flex u-flex-end" style="padding-right: 20rpx">
							<u-tag text="删除" type="error" @click="ondel(item)"></u-tag>
						</view>
					</template>
				</listcard>
			</template>
		</getdatascrollview>
		<sxpopup ref="sxpopup" :searchdata="searchdata"></sxpopup>
	</view>
</template>

<script>
	import {
		getCompanyFilePage,
		deleteCompanyFile,
	} from "@/api/company/companyFile";
	// import sxpopup from "./components/sxpopup.vue";
	export default {
		components: {
			// sxpopup,
		},
		data() {
			return {
				customstyle: {
					margin: 0,
					flex: 0,
				},
				tablequery: {},
				api: getCompanyFilePage,
				searchdata: {},
				searchinputs: [{
						label: "资料名称",
						value: "name",
					},
					{
						label: "资料类型",
						value: "dataType",
						type: "select",
						option: this.$store.state.dict.dictDatas[
							this.$store.state.dict.DICT_TYPE.BUSI_MANG_FILETYPE
						],
					},
				],
				listinputs: [
					// {
					//   label: "所属部门",
					//   value: "deptName",
					// },
					{
						label: "资料名称",
						value: "name",
					},
					{
						label: "资料类型",
						value: "dataType",
						type: "select",
						option: this.$store.state.dict.dictDatas[
							this.$store.state.dict.DICT_TYPE.BUSI_MANG_FILETYPE
						],
					},
					{
						label: "文件",
						value: "file",
						type: "file",
					},
					{
						label: "开始日期",
						value: "startTime",
						type: "date",
					},
					{
						label: "到期日期",
						value: "endTime",
						type: "date",
					},
				],
			};
		},
		onShow() {
			this.$refs.getdatascrollview && this.$refs.getdatascrollview.onRefresh();
		},
		methods: {
			change() {
				// console.log(this.searchdata.deptId, "this.tablequery");
				this.onsearch();
			},
			sxfn() {
				this.$refs.sxpopup.open(this.searchinputs).then((data) => {
					this.searchdata = {
						...this.searchdata,
						...data,
					};
					this.onsearch();
				});
			},
			async onsearch() {
				this.tablequery = {
					...this.searchdata,
				};

				this.$nextTick(() => {
					this.$refs.getdatascrollview.onRefresh();
				});
			},
			ondel(row) {
				console.log(row);
				uni.showModal({
					title: "提示",
					content: "是否删除此数据？",
					success: (res) => {
						if (res.confirm) {
							deleteCompanyFile([row.uuid]).then((e) => {
								this.onsearch();
							});
						} else if (res.cancel) {
							console.log("用户点击取消");
						}
					},
				});
			},
			onedt() {
				uni.navigateTo({
					url: "/pageswork/company/fileInfo/edit",
				});
			},
		},
	};
</script>
<style>
	page {
		background: #fff;
	}
</style>
<style lang="scss" scoped>
	.edtbtn {
		color: #1890ff;
		font-size: 28rpx;
	}

	.searchcontent {
		display: flex;
		align-items: center;
		padding: 20rpx 20rpx 0 20rpx;

		.sx {
			padding-left: 20rpx;
			display: flex;
			font-size: 28rpx;
		}
	}
</style>